home *** CD-ROM | disk | FTP | other *** search
/ PC Open 107 / PC Open 107 CD 1.bin / CD1 / INTERNET / COPIA SITI / HTTrack / httrack.exe / {app} / src_win / WinHTTrack / newlang.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-11  |  21.8 KB  |  768 lines

  1.  
  2. // Win includes
  3. #include "stdafx.h"
  4. #include "Shell.h"
  5. #include <comdef.h>
  6.  
  7. // Hash for lang.h
  8. extern "C" {
  9.   #include "HTTrackInterface.h"
  10. #define HTS_INTERNAL_BYTECODE
  11.   #include "htsinthash.h"
  12. #undef HTS_INTERNAL_BYTECODE
  13. };
  14. #include "newlang.h"
  15.  
  16. // test
  17. #ifndef _MBCS
  18. #error "MBCS/DBCS support not found"
  19. #endif
  20. #include <locale.h>
  21.  
  22.  
  23. int NewLangStrSz=1024;
  24. inthash NewLangStr=NULL;
  25. int NewLangStrKeysSz=1024;
  26. inthash NewLangStrKeys=NULL;
  27. UINT NewLangCP = CP_THREAD_ACP;
  28. UINT NewLangFileCP = CP_THREAD_ACP;
  29.  
  30. typedef struct WinLangid {
  31.   int langId;
  32.   const char* name;
  33. } WinLangid;
  34.  
  35. WinLangid WINDOWS_LANGID[] = {
  36.   { 0x0436, "Afrikaans" },
  37.   { 0x041c, "Albanian" },
  38.   { 0x0401, "Arabic (Saudi Arabia)" },
  39.   { 0x0801, "Arabic (Iraq)" },
  40.   { 0x0c01, "Arabic (Egypt)" },
  41.   { 0x1001, "Arabic (Libya)" },
  42.   { 0x1401, "Arabic (Algeria)" },
  43.   { 0x1801, "Arabic (Morocco)" },
  44.   { 0x1c01, "Arabic (Tunisia)" },
  45.   { 0x2001, "Arabic (Oman)" },
  46.   { 0x2401, "Arabic (Yemen)" },
  47.   { 0x2801, "Arabic (Syria)" },
  48.   { 0x2c01, "Arabic (Jordan)" },
  49.   { 0x3001, "Arabic (Lebanon)" },
  50.   { 0x3401, "Arabic (Kuwait)" },
  51.   { 0x3801, "Arabic (U.A.E.)" },
  52.   { 0x3c01, "Arabic (Bahrain)" },
  53.   { 0x4001, "Arabic (Qatar)" },
  54.   { 0x042b, "Armenian" },
  55.   { 0x042c, "Azeri (Latin)" },
  56.   { 0x082c, "Azeri (Cyrillic)" },
  57.   { 0x042d, "Basque" },
  58.   { 0x0423, "Belarusian" },
  59.   { 0x0445, "Bengali (India)" },
  60.   { 0x141a, "Bosnian (Bosnia and Herzegovina)" },
  61.   { 0x0402, "Bulgarian" },
  62.   { 0x0455, "Burmese" },
  63.   { 0x0403, "Catalan" },
  64.   { 0x0404, "Chinese (Taiwan)" },
  65.   { 0x0804, "Chinese (PRC)" },
  66.   { 0x0c04, "Chinese (Hong Kong SAR, PRC)" },
  67.   { 0x1004, "Chinese (Singapore)" },
  68.   { 0x1404, "Chinese (Macao SAR)" },
  69.   { 0x041a, "Croatian" },
  70.   { 0x101a, "Croatian (Bosnia and Herzegovina)" },
  71.   { 0x0405, "Czech" },
  72.   { 0x0406, "Danish" },
  73.   { 0x0465, "Divehi" },
  74.   { 0x0413, "Dutch (Netherlands)" },
  75.   { 0x0813, "Dutch (Belgium)" },
  76.   { 0x0409, "English (United States)" },
  77.   { 0x0809, "English (United Kingdom)" },
  78.   { 0x0c09, "English (Australian)" },
  79.   { 0x1009, "English (Canadian)" },
  80.   { 0x1409, "English (New Zealand)" },
  81.   { 0x1809, "English (Ireland)" },
  82.   { 0x1c09, "English (South Africa)" },
  83.   { 0x2009, "English (Jamaica)" },
  84.   { 0x2409, "English (Caribbean)" },
  85.   { 0x2809, "English (Belize)" },
  86.   { 0x2c09, "English (Trinidad)" },
  87.   { 0x3009, "English (Zimbabwe)" },
  88.   { 0x3409, "English (Philippines)" },
  89.   { 0x0425, "Estonian" },
  90.   { 0x0438, "Faeroese" },
  91.   { 0x0429, "Farsi" },
  92.   { 0x040b, "Finnish" },
  93.   { 0x040c, "French (Standard)" },
  94.   { 0x080c, "French (Belgian)" },
  95.   { 0x0c0c, "French (Canadian)" },
  96.   { 0x100c, "French (Switzerland)" },
  97.   { 0x140c, "French (Luxembourg)" },
  98.   { 0x180c, "French (Monaco)" },
  99.   { 0x0456, "Galician" },
  100.   { 0x0437, "Georgian" },
  101.   { 0x0407, "German (Standard)" },
  102.   { 0x0807, "German (Switzerland)" },
  103.   { 0x0c07, "German (Austria)" },
  104.   { 0x1007, "German (Luxembourg)" },
  105.   { 0x1407, "German (Liechtenstein)" },
  106.   { 0x0408, "Greek" },
  107.   { 0x0447, "Gujarati" },
  108.   { 0x040d, "Hebrew" },
  109.   { 0x0439, "Hindi" },
  110.   { 0x040e, "Hungarian" },
  111.   { 0x040f, "Icelandic" },
  112.   { 0x0421, "Indonesian" },
  113.   { 0x0434, "isiXhosa/Xhosa (South Africa)" },
  114.   { 0x0435, "isiZulu/Zulu (South Africa)" },
  115.   { 0x0410, "Italian (Standard)" },
  116.   { 0x0810, "Italian (Switzerland)" },
  117.   { 0x0411, "Japanese" },
  118.   { 0x044b, "Kannada" },
  119.   { 0x0457, "Konkani" },
  120.   { 0x0412, "Korean" },
  121.   { 0x0812, "Korean (Johab)" },
  122.   { 0x0440, "Kyrgyz" },
  123.   { 0x0426, "Latvian" },
  124.   { 0x0427, "Lithuanian" },
  125.   { 0x0827, "Lithuanian (Classic)" },
  126.   { 0x042f, "FYRO Macedonian" },
  127.   { 0x043e, "Malay (Malaysian)" },
  128.   { 0x083e, "Malay (Brunei Darussalam)" },
  129.   { 0x044c, "Malayalam (India)" },
  130.   { 0x0481, "Maori (New Zealand)" },
  131.   { 0x043a, "Maltese (Malta)" },
  132.   { 0x044e, "Marathi" },
  133.   { 0x0450, "Mongolian" },
  134.   { 0x0414, "Norwegian (Bokmal)" },
  135.   { 0x0814, "Norwegian (Nynorsk)" },
  136.   { 0x0415, "Polish" },
  137.   { 0x0416, "Portuguese (Brazil)" },
  138.   { 0x0816, "Portuguese (Portugal)" },
  139.   { 0x0446, "Punjabi" },
  140.   { 0x046b, "Quechua (Bolivia)" },
  141.   { 0x086b, "Quechua (Ecuador)" },
  142.   { 0x0c6b, "Quechua (Peru)" },
  143.   { 0x0418, "Romanian" },
  144.   { 0x0419, "Russian" },
  145.   { 0x044f, "Sanskrit" },
  146.   { 0x043b, "Sami, Northern (Norway)" },
  147.   { 0x083b, "Sami, Northern (Sweden)" },
  148.   { 0x0c3b, "Sami, Northern (Finland)" },
  149.   { 0x103b, "Sami, Lule (Norway)" },
  150.   { 0x143b, "Sami, Lule (Sweden)" },
  151.   { 0x183b, "Sami, Southern (Norway)" },
  152.   { 0x1c3b, "Sami, Southern (Sweden)" },
  153.   { 0x203b, "Sami, Skolt (Finland)" },
  154.   { 0x243b, "Sami, Inari (Finland)" },
  155.   { 0x0c1a, "Serbian (Cyrillic)" },
  156.   { 0x1c1a, "Serbian (Cyrillic, Bosnia, and Herzegovina)" },
  157.   { 0x081a, "Serbian (Latin)" },
  158.   { 0x181a, "Serbian (Latin, Bosnia, and Herzegovina)" },
  159.   { 0x046c, "Sesotho sa Leboa/Northern Sotho (South Africa)" },
  160.   { 0x0432, "Setswana/Tswana (South Africa)" },
  161.   { 0x041b, "Slovak" },
  162.   { 0x0424, "Slovenian" },
  163.   { 0x040a, "Spanish (Spain, Traditional Sort)" },
  164.   { 0x080a, "Spanish (Mexican)" },
  165.   { 0x0c0a, "Spanish (Spain, Modern Sort)" },
  166.   { 0x100a, "Spanish (Guatemala)" },
  167.   { 0x140a, "Spanish (Costa Rica)" },
  168.   { 0x180a, "Spanish (Panama)" },
  169.   { 0x1c0a, "Spanish (Dominican Republic)" },
  170.   { 0x200a, "Spanish (Venezuela)" },
  171.   { 0x240a, "Spanish (Colombia)" },
  172.   { 0x280a, "Spanish (Peru)" },
  173.   { 0x2c0a, "Spanish (Argentina)" },
  174.   { 0x300a, "Spanish (Ecuador)" },
  175.   { 0x340a, "Spanish (Chile)" },
  176.   { 0x380a, "Spanish (Uruguay)" },
  177.   { 0x3c0a, "Spanish (Paraguay)" },
  178.   { 0x400a, "Spanish (Bolivia)" },
  179.   { 0x440a, "Spanish (El Salvador)" },
  180.   { 0x480a, "Spanish (Honduras)" },
  181.   { 0x4c0a, "Spanish (Nicaragua)" },
  182.   { 0x500a, "Spanish (Puerto Rico)" },
  183.   { 0x0430, "Sutu" },
  184.   { 0x0441, "Swahili (Kenya)" },
  185.   { 0x041d, "Swedish" },
  186.   { 0x081d, "Swedish (Finland)" },
  187.   { 0x045a, "Syriac" },
  188.   { 0x0449, "Tamil" },
  189.   { 0x0444, "Tatar (Tatarstan)" },
  190.   { 0x044a, "Telugu" },
  191.   { 0x041e, "Thai" },
  192.   { 0x041f, "Turkish" },
  193.   { 0x0422, "Ukrainian" },
  194.   { 0x0420, "Urdu (Pakistan)" },
  195.   { 0x0820, "Urdu (India)" },
  196.   { 0x0443, "Uzbek (Latin)" },
  197.   { 0x0843, "Uzbek (Cyrillic)" },
  198.   { 0x042a, "Vietnamese" },
  199.   { 0x0452, "Welsh (United Kingdom)" },
  200.   { 0, NULL }
  201. };
  202.  
  203. void LANG_LOAD(char* limit_to) {
  204.   CWaitCursor wait;
  205.   //
  206.   extern int NewLangStrSz;
  207.   extern inthash NewLangStr;
  208.   extern int NewLangStrKeysSz;
  209.   extern inthash NewLangStrKeys;
  210.   //
  211.   int selected_lang=LANG_T(-1);
  212.   //
  213.   if (!limit_to) {
  214.     LANG_DELETE();
  215.     NewLangStr=inthash_new(NewLangStrSz);
  216.     NewLangStrKeys=inthash_new(NewLangStrKeysSz);
  217.     if ((NewLangStr==NULL) || (NewLangStrKeys==NULL)) {
  218.       AfxMessageBox("Error in lang.h: not enough memory");
  219.     } else {
  220.       inthash_value_is_malloc(NewLangStr,1);
  221.       inthash_value_is_malloc(NewLangStrKeys,1);
  222.     }
  223.   }
  224.  
  225.   CString app;
  226.   CWinApp* pApp = AfxGetApp();
  227.   if (pApp) {
  228.     app=pApp->m_pszHelpFilePath;
  229.     app=app.Left(app.ReverseFind('\\')+1);
  230.   }
  231.  
  232.   /* Load master file (list of keys and internal keys) */
  233.   if (!limit_to) {
  234.     CString mname=app+"lang.def";
  235.     if (!fexist((char*)LPCTSTR(mname)))
  236.       mname="lang.def";
  237.     FILE* fp=fopen(mname,"rb");
  238.     if (fp) {
  239.       char intkey[8192];
  240.       char key[8192];
  241.       while(!feof(fp)) {
  242.         linput_cpp(fp,intkey,8000);
  243.         linput_cpp(fp,key,8000);
  244.         if (strnotempty(intkey) && strnotempty(key)) {
  245.           char* test=LANGINTKEY(key);
  246.  
  247.           /* Increment for multiple definitions */
  248.           if (strnotempty(test)) {
  249.             int increment=0;
  250.             int pos=strlen(key);
  251.             do {
  252.               increment++;
  253.               sprintf(key+pos,"%d",increment);
  254.               test=LANGINTKEY(key);
  255.             }  while (strnotempty(test));
  256.           }
  257.  
  258.           if (!strnotempty(test)) {         // Θviter doublons
  259.             // conv_printf(key,key);
  260.             int len;
  261.             char* buff;
  262.             len=strlen(intkey);
  263.             buff=(char*)malloc(len+2);
  264.             if (buff) {
  265.               strcpybuff(buff,intkey);
  266.               inthash_add(NewLangStrKeys,key,(long int)(char*)buff);
  267.             }
  268.           }
  269.         } // if
  270.       }  // while
  271.       fclose(fp);
  272.     } else {
  273.       AfxMessageBox("FATAL ERROR\r\n'lang.def' file NOT FOUND!\r\nEnsure that the installation was complete!");
  274.       exit(0);
  275.     }
  276.   }
  277.   
  278.   /* Language Name? */
  279.   char* hashname;
  280.   {
  281.     char name[256];
  282.     sprintf(name,"LANGUAGE_%d",selected_lang+1);
  283.     hashname=LANGINTKEY(name);
  284.   }
  285.  
  286.   /* Get only language name */
  287.   if (limit_to) {
  288.     if (hashname)
  289.       strcpybuff(limit_to,hashname);
  290.     else
  291.       strcpybuff(limit_to,"???");
  292.     return;
  293.   }
  294.  
  295.   /* Error */
  296.   if (!hashname)
  297.     return;
  298.  
  299.   // xxc TEST
  300.   /*
  301.   setlocale( LC_ALL, "Japanese");
  302.   _setmbcp(932);    // shift-jis
  303.   setlocale( LC_ALL, ".932" );
  304.   setlocale( LC_ALL, "[.932]" );
  305.   CString st="";
  306.   int lid=SetThreadLocale(MAKELCID(MAKELANGID(LANG_JAPANESE,SUBLANG_NEUTRAL),SORT_DEFAULT ));
  307.   */
  308.  
  309.   /* Load specific language file */
  310.   {
  311.     int loops;
  312.     CString err_msg="";
  313.     // 2nd loop: load undefined strings
  314.     for(loops=0;loops<2;loops++) {
  315.       CString lbasename;
  316.       
  317.       {
  318.         char name[256];
  319.         sprintf(name,"LANGUAGE_%d",(loops==0)?(selected_lang+1):1);
  320.         hashname=LANGINTKEY(name);
  321.       }
  322.       lbasename.Format("lang/%s.txt",hashname);
  323.       CString lname=app+lbasename;
  324.       if (!fexist((char*)LPCTSTR(lname)))
  325.         lname=lbasename;
  326.       FILE* fp=fopen(lname,"rb");
  327.       if (fp) {
  328.         char extkey[8192];
  329.         TCHAR value[8192];
  330.         while(!feof(fp)) {
  331.           //int ssz;
  332.           linput_cpp(fp,extkey,8000);
  333.           linput_cpp(fp,value,8000);
  334.           /*
  335.           ssz=linput_cpp(fp,value,8000);
  336.           CString st=value;
  337.           AfxMessageBox(st);
  338.           if (ssz>0) {
  339.             int tst=0;
  340.             int test=IsTextUnicode(value,ssz,&tst);
  341.             unsigned short st2[1024];
  342.             int ret=MultiByteToWideChar(CP_UTF8,0,(char*)value,ssz,st2,1024);
  343.             if (ret>0) {
  344.               char st3[1024]="";
  345.               int ret2=WideCharToMultiByte(CP_THREAD_ACP,0,st2,ret,(char*)st3,1024,NULL,FALSE);
  346.               if (ret2>0) {
  347.                 AfxMessageBox(st3);
  348.               }
  349.             }
  350.           }
  351.           */
  352.  
  353.           if (strnotempty(extkey) && strnotempty(value)) {
  354.             int len;
  355.             char* buff;
  356.             char* intkey;
  357.             
  358.             intkey=LANGINTKEY(extkey);
  359.             
  360.             if (strnotempty(intkey)) {
  361.               
  362.               /* Increment for multiple definitions */
  363.               {
  364.                 char* test=LANGSEL(intkey);
  365.                 if (strnotempty(test)) {
  366.                   if (loops == 0) {
  367.                     int increment=0;
  368.                     int pos=strlen(extkey);
  369.                     do {
  370.                       increment++;
  371.                       sprintf(extkey+pos,"%d",increment);
  372.                       intkey=LANGINTKEY(extkey);
  373.                       if (strnotempty(intkey))
  374.                         test=LANGSEL(intkey);
  375.                       else
  376.                         test="";
  377.                     }  while (strnotempty(test));
  378.                   } else
  379.                     intkey="";
  380.                 } else {
  381.                   if (loops > 0) {
  382.                     err_msg += intkey;
  383.                     err_msg += " ";
  384.                   }
  385.                 }
  386.               }
  387.               
  388.               /* Add key */
  389.               if (strnotempty(intkey)) {
  390.                 len=strlen(value);
  391.                 buff=(char*)malloc(len+2);
  392.                 if (buff) {
  393.                   conv_printf(value,buff);
  394.                   inthash_add(NewLangStr,intkey,(long int)(char*)buff);
  395.                 }
  396.               }
  397.               
  398.             }
  399.           } // if
  400.         }  // while
  401.         fclose(fp);
  402.       } else {
  403.         AfxMessageBox("FATAL ERROR\r\n'lang.def' file NOT FOUND!\r\nEnsure that the installation was complete!");
  404.         exit(0);
  405.       }
  406.     }
  407.     if (err_msg.GetLength()>0) {
  408.       // AfxMessageBox("Error: undefined strings follows:\r\n"+err_msg);
  409.     }
  410.   }
  411.  
  412.  
  413.  
  414. #if 0
  415.   app=app+"lang.h";
  416.   if (!fexist((char*)LPCTSTR(app)))
  417.     app="lang.h";
  418.   
  419.   FILE* fp=fopen(app,"rb");
  420.   if (fp) {
  421.     char s[8192];
  422.     while(!feof(fp)) {
  423.       linput_cpp(fp,s,8000);
  424.       if (!strncmp(s,"#define ",8)) {
  425.         char* a;
  426.         char* name=s+8;
  427.         a=name;
  428.         while((*a!=' ') && (*a)) a++;
  429.         if ((*a) && (strlen(name)>0) && (((int) a - (int) name)<64)) {
  430.           *a++='\0';
  431.           if (limit_to) {
  432.             if (strcmp(name,limit_to))
  433.               a=NULL;
  434.           }
  435.           if (a) {
  436.             char* data;
  437.             data=a;
  438.             int toggle=0;
  439.             char* start_str=NULL;
  440.             int count=0;
  441.             while(*a) {
  442.               if (*a=='\"') {
  443.                 toggle++;
  444.                 if ((toggle%2)==1) {
  445.                   if (count==selected_lang) {
  446.                     start_str=a+1;
  447.                   }
  448.                   count++;
  449.                 } else {
  450.                   if (start_str) {
  451.                     char* buff;
  452.                     int len;
  453.                     len=(int) a - (int) start_str;
  454.                     if (len) {
  455.                       buff=(char*)malloc(len+2);
  456.                       if (buff) {
  457.                         int i=0,j=0;
  458.                         buff[0]='\0';
  459.                         //strncatbuff(buff,start_str,len);
  460.                         while(i<len) {
  461.                           switch(start_str[i]) {
  462.                           case '\\': 
  463.                             i++;
  464.                             switch(start_str[i]) {
  465.                             case 'a': buff[j]='\a'; break;
  466.                             case 'b': buff[j]='\b'; break;
  467.                             case 'f': buff[j]='\f'; break;
  468.                             case 'n': buff[j]='\n'; break;
  469.                             case 'r': buff[j]='\r'; break;
  470.                             case 't': buff[j]='\t'; break;
  471.                             case 'v': buff[j]='\v'; break;
  472.                             case '\'': buff[j]='\''; break;
  473.                             case '\"': buff[j]='\"'; break;
  474.                             case '\\': buff[j]='\\'; break;
  475.                             case '?': buff[j]='\?'; break;
  476.                             default: buff[j]=start_str[i]; break;
  477.                             }
  478.                             break;
  479.                             default: 
  480.                               buff[j]=start_str[i]; 
  481.                               break;
  482.                           }
  483.                           i++;
  484.                           j++;
  485.                         }
  486.                         buff[j++]='\0';
  487.                         if (!limit_to)
  488.                           inthash_add(NewLangStr,name,(long int)(char*)buff);
  489.                         else {
  490.                           strcpybuff(limit_to,buff);
  491.                           free(buff);
  492.                           return;
  493.                         }
  494.                       }
  495.                     }
  496.                     start_str=NULL;
  497.                   }
  498.                 }
  499.               }
  500.               a++;
  501.             }
  502.           }
  503.           
  504.           //NewLangStr.SetAt(sname,st);
  505.           /*
  506.           } else {
  507.           CString info;
  508.           info.Format("Error in lang.h: %s",name);
  509.           AfxMessageBox(info);
  510.         */
  511.         }
  512.       }
  513.     }
  514.  
  515.  
  516.     fclose(fp);
  517.  
  518.   } else {
  519.     AfxMessageBox("FATAL ERROR\r\n'lang.h' file NOT FOUND!\r\nEnsure that the installation was complete!");
  520.     exit(0);
  521.   }
  522. #endif
  523.  
  524.   // Control limit_to
  525.   if (limit_to)
  526.     limit_to[0]='\0';
  527.  
  528.   // Set locale
  529.   if (!limit_to) {
  530.     CString charset = LANGUAGE_CHARSET;
  531.     charset.TrimLeft();
  532.     charset.TrimRight();
  533.     charset.MakeLower();
  534.     NewLangCP = CP_THREAD_ACP;
  535.     NewLangFileCP = CP_THREAD_ACP;
  536. #if 0
  537.     if (charset.GetLength() > 0) {
  538.       if (charset.Left(9) == "iso-8859-") {
  539.         int iso = 0;
  540.         int isoCP[] = {0, /* 0 */
  541.           1252, /* ISO-8859-1 */
  542.           1250, /* ISO-8859-2 */
  543.           0, /* ISO-8859-3 */
  544.           0, /* ISO-8859-4 */
  545.           1251, /* ISO-8859-5 */
  546.           1256, /* ISO-8859-6 */
  547.           1253, /* ISO-8859-7 */
  548.           1255, /* ISO-8859-8 */
  549.           1254, /* ISO-8859-9 */
  550.         };
  551.         if (sscanf(charset.GetBuffer(0) + 9, "%d", &iso) == 1) {
  552.           if (iso < sizeof(isoCP)/sizeof(isoCP[0])) {
  553.             if (isoCP[iso] != 0) {
  554.               NewLangFileCP = isoCP[iso];
  555.             }
  556.           }
  557.         }
  558.       } else if (charset.Left(8) == "windows-") {
  559.         int windows = 0;
  560.         if (sscanf(charset.GetBuffer(0) + 8, "%d", &windows) == 1) {
  561.           NewLangFileCP = windows;
  562.         }
  563.       } else if (charset == "shift-jis") {
  564.         NewLangFileCP = 932;
  565.       } else if (charset == "big5") {
  566.         NewLangFileCP = 950;
  567.       } else if (charset == "gb2312") {
  568.         NewLangFileCP = 936;
  569.       } else {
  570.         NewLangFileCP = CP_THREAD_ACP;
  571.       }
  572.     }
  573.     WORD acp = GetACP();
  574.     if (NewLangFileCP != CP_THREAD_ACP && NewLangFileCP != acp) {
  575.       char* currName = LANGUAGE_WINDOWSID;
  576.       LCID thl = GetThreadLocale();
  577.       WORD sid = SORTIDFROMLCID(thl);
  578.       WORD lid = 0;
  579.       WinLangid* lids;
  580.       if (currName[0]) {
  581.         for( lids = (WinLangid*)&WINDOWS_LANGID ; lids->name != NULL ; lids++ ) {
  582.           if (strcmp(currName, lids->name) == 0) {
  583.             lid = lids->langId;
  584.             break;
  585.           }
  586.         }
  587.         if (lid != 0) {
  588.           SetThreadLocale(MAKELCID(lid, sid));
  589.         }
  590.       }
  591.     }
  592. #endif
  593.  
  594.   }
  595.  
  596. }
  597.  
  598. void conv_printf(char* from,char* to) {
  599.   int i=0,j=0,len;
  600.   len=strlen(from);
  601.   while(i<len) {
  602.     switch(from[i]) {
  603.     case '\\': 
  604.       i++;
  605.       switch(from[i]) {
  606.       case 'a': to[j]='\a'; break;
  607.       case 'b': to[j]='\b'; break;
  608.       case 'f': to[j]='\f'; break;
  609.       case 'n': to[j]='\n'; break;
  610.       case 'r': to[j]='\r'; break;
  611.       case 't': to[j]='\t'; break;
  612.       case 'v': to[j]='\v'; break;
  613.       case '\'': to[j]='\''; break;
  614.       case '\"': to[j]='\"'; break;
  615.       case '\\': to[j]='\\'; break;
  616.       case '?': to[j]='\?'; break;
  617.       default: to[j]=from[i]; break;
  618.       }
  619.       break;
  620.       default: 
  621.         to[j]=from[i]; 
  622.         break;
  623.     }
  624.     i++;
  625.     j++;
  626.   }
  627.   to[j++]='\0';
  628. }
  629.  
  630. void LANG_DELETE() {
  631.   extern int NewLangStrSz;
  632.   extern inthash NewLangStr;
  633.   extern int NewLangStrKeysSz;
  634.   extern inthash NewLangStrKeys;
  635.   //
  636.   inthash_delete(&NewLangStr);
  637.   inthash_delete(&NewLangStrKeys);
  638. }
  639.  
  640. // sΘlection de la langue
  641. void LANG_INIT() {
  642.   CWinApp* pApp = AfxGetApp();
  643.   if (pApp) {
  644.     int test = pApp->GetProfileInt("Language","IntId",0);
  645.     LANG_T(pApp->GetProfileInt("Language","IntId",0));
  646.   }
  647. }
  648.  
  649. int LANG_T(int l) {
  650.   if (l>=0) {
  651.     QLANG_T(l);
  652.     CWinApp* pApp = AfxGetApp();
  653.     if (pApp)
  654.       pApp->WriteProfileInt("Language","IntId",l);
  655.     LANG_LOAD(NULL);
  656.   }
  657.   return QLANG_T(-1);  // 0=default (english)
  658. }
  659.  
  660. int QLANG_T(int l) {
  661.   static int lng=0;
  662.   if (l>=0) {
  663.     lng=l;
  664.   }
  665.   return lng;  // 0=default (english)
  666. }
  667.  
  668.  
  669. /*
  670. char* LANGSEL(char* lang0,...) {
  671.   char* lang=lang0;
  672.   char* langalt="";
  673.   int langid=LANG_T(-1);
  674.   //
  675.   va_list argList;
  676.     va_start(argList, lang0);
  677.   while(langid>0) {
  678.     if (lang) {
  679.       if (strlen(langalt)==0) {
  680.         if (strlen(lang)>0)
  681.           langalt=lang;
  682.       }
  683.     }
  684.     langid--;
  685.     lang=va_arg(argList, char*);
  686.   }
  687.   va_end(argList);
  688.   //
  689.   if (!lang)
  690.     return langalt;
  691.   if (strlen(lang)==0)
  692.     return langalt;
  693.   return lang;
  694. }
  695. */
  696.  
  697. char* LANGSEL(char* name) {
  698.   unsigned long int adr=NULL;
  699.   if (NewLangStr)
  700.   if (!inthash_read(NewLangStr,name,(long int *)&adr))
  701.     adr=NULL;
  702.   if (adr) {
  703.     return (char*)adr;
  704.   }
  705.   return "";
  706. }
  707.  
  708. char* LANGINTKEY(char* name) {
  709.   unsigned long int adr=NULL;
  710.   if (NewLangStrKeys)
  711.   if (!inthash_read(NewLangStrKeys,name,(long int *)&adr))
  712.     adr=NULL;
  713.   if (adr) {
  714.     return (char*)adr;
  715.   }
  716.   return "";
  717. }
  718.  
  719. static _bstr_t ConvertCodepage(LPCSTR str, UINT codePage)
  720. {
  721.   _bstr_t returnValue;
  722.   BOOL ok = TRUE;
  723.   int mbLength = strlen(str);
  724.   int wideLength = ::MultiByteToWideChar( codePage, 0, str, mbLength, NULL, NULL); 
  725.   if (wideLength > 0) 
  726.   {
  727.     wchar_t *wcharBuffer = new wchar_t[wideLength+1]; 
  728.     ::MultiByteToWideChar( codePage, 0, str, mbLength, wcharBuffer, wideLength); 
  729.     wcharBuffer[wideLength] = '\0';
  730.     returnValue = wcharBuffer;
  731.     delete wcharBuffer;
  732.   }
  733.   return returnValue;
  734. }
  735.  
  736. BOOL SetDlgItemTextCP(HWND hDlg, int nIDDlgItem, LPCSTR lpString) {
  737.   if (NewLangCP != CP_THREAD_ACP)
  738.     return SetDlgItemTextW(hDlg, nIDDlgItem, ConvertCodepage(lpString, NewLangCP));
  739.   else
  740.     return SetDlgItemTextA(hDlg, nIDDlgItem, lpString);
  741. }
  742.  
  743. BOOL SetDlgItemTextCP(CWnd* wnd, int nIDDlgItem, LPCSTR lpString) {
  744.   return SetDlgItemTextCP(wnd->m_hWnd, nIDDlgItem, lpString);
  745. }
  746.  
  747. BOOL SetWindowTextCP(HWND hWnd, LPCSTR lpString) {
  748.   if (NewLangCP != CP_THREAD_ACP)
  749.     return SetWindowTextW(hWnd, ConvertCodepage(lpString, NewLangCP));
  750.   else
  751.     return SetWindowTextA(hWnd, lpString);
  752. }
  753.  
  754. BOOL SetWindowTextCP(CWnd* wnd, LPCSTR lpString) {
  755.   return SetWindowTextCP(wnd->m_hWnd, lpString);
  756. }
  757.  
  758. BOOL ModifyMenuCP(HMENU hMnu, UINT uPosition, UINT uFlags, UINT uIDNewItem, LPCSTR lpNewItem) {
  759.   if (NewLangCP != CP_THREAD_ACP)
  760.     return ModifyMenuW(hMnu, uPosition, uFlags, uIDNewItem, ConvertCodepage(lpNewItem, NewLangCP));
  761.   else
  762.     return ModifyMenuA(hMnu, uPosition, uFlags, uIDNewItem, lpNewItem);
  763. }
  764.  
  765. BOOL ModifyMenuCP(CMenu* menu, UINT uPosition, UINT uFlags, UINT uIDNewItem, LPCSTR lpNewItem) {
  766.   return ModifyMenuCP(menu->m_hMenu, uPosition, uFlags, uIDNewItem, lpNewItem);
  767. }
  768.